package com.guigu.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.OrderService;
import com.guigu.mapper.OrderMapper;
import com.guigu.pojo.Businesses;
import com.guigu.pojo.Order;
import com.guigu.vo.Pojo;
import com.guigu.vo.Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Pojo<Order> getPage(int pageNum, int pageSize, Vo vo) {
        //设置页号
        PageHelper.startPage(pageNum,pageSize);
        List<Order> orders = orderMapper.selectAll(vo);
        PageInfo<Order> orderPageInfo = new PageInfo<>(orders);
        Pojo<Order> orderPojo = new Pojo<>();
        orderPojo.setRows(orderPageInfo.getList());
        orderPojo.setTotal(orderPageInfo.getTotal());
        return orderPojo;
    }

    @Override
    public Businesses selectById(int userId) {
       return orderMapper.selectById(userId);
    }

    @Override
    public Order selectMaxId() {
        Order order = orderMapper.selectMaxId();
        if(Objects.equals(null,order) ){
            return null;
        }
        return order;
    }

    @Override
    public int insert(Order order) {
        return orderMapper.insert(order);
    }

    @Override
    public Order One(String orderId) {
        Order one = orderMapper.One(orderId);
        return one;
    }

    @Override
    public int update(Order order) {
        return orderMapper.update(order);
    }
}
